package com.atguigu06.polymorphism.exer2;

/**
 * ClassName: AnimalTest
 * Package: com.atguigu06.polymorphism.apply
 * Description:
 *
 * @Author ZY
 * @Create 19:18
 * @Version 1.0
 */
public class AnimalTest {

    public static void main(String[] args) {

        AnimalTest test = new AnimalTest();

        test.func(new Dog());
        test.func(new Cat());

    }

    public void func(Animal animal){ //Animal animal = new Dog()
        animal.eat();
        animal.jump();


        //强转
        if(animal instanceof Dog){
            Dog dog = (Dog)animal;
            dog.lookDoor();
        } else if (animal instanceof Cat) {
            Cat cat = (Cat)animal;
            cat.catchMouse();
        }

    }



}

class Animal {

    public void eat(){
        System.out.println("动物吃食");
    }

    public void jump(){
        System.out.println("动物跳");
    }
}

class Dog extends Animal{
    public void eat(){
        System.out.println("狗吃狗粮");
    }

    public void jump(){
        System.out.println("狗跳");
    }

    public void lookDoor(){
        System.out.println("狗看门");
    }
}

class Cat extends Animal{
    public void eat(){
        System.out.println("猫吃猫粮");
    }

    public void jump(){
        System.out.println("猫跳");
    }

    public void catchMouse(){
        System.out.println("猫抓老鼠");
    }
}
